﻿<!--
// ****************************************************************************
// <author>mishkin Ivan</author>
// <email>Mishkin_Ivan@mail.ru</email>
// <date>28.01.2015</date>
// <project>ItemsFilter</project>
// <license> GNU General Public License version 3 (GPLv3) </license>
// ****************************************************************************
-->
<bsFilter:MultiValueFilterView x:Class="Northwind.NET.Sample.View.CategoryFilterView"
                               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                               xmlns:bsFilter="http://schemas.bolapansoft.com/xaml/Controls/ItemsFilter"
                               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                               xmlns:local="clr-namespace:Northwind.NET.Sample"
                               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                               xmlns:shader="clr-namespace:Shazzam.Shaders"
                               xmlns:vw="clr-namespace:Northwind.NET.Sample.View"
                               ToolTip="Choose categories to view."
                               d:DesignHeight="150"
                               d:DesignWidth="300"
                               mc:Ignorable="d">
    <bsFilter:MultiValueFilterView.Resources>
        <vw:BoolToEffectConverter x:Key="BoolToEffectConverter" />
        <ItemsPanelTemplate x:Key="CategoryItemsPanelTemplate">
            <StackPanel IsItemsHost="True" Orientation="Horizontal" />
        </ItemsPanelTemplate>

    </bsFilter:MultiValueFilterView.Resources>
    <bsFilter:MultiValueFilterView.Style>
        <Style TargetType="{x:Type bsFilter:MultiValueFilterView}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type bsFilter:MultiValueFilterView}">
                        <Border>
                            <Border.Style>
                                <Style TargetType="{x:Type Border}">
                                    <Setter Property="BorderBrush" Value="#FF9D5C5C" />
                                    <Setter Property="CornerRadius" Value="2" />
                                    <Setter Property="BorderThickness" Value="1" />
                                    <Setter Property="Width" Value="Auto" />
                                    <Setter Property="MinWidth" Value="150" />
                                    <Setter Property="Background">
                                        <Setter.Value>
                                            <LinearGradientBrush StartPoint="0.5,1" EndPoint="0.5,0">
                                                <GradientStop Color="#FFFEFEFE" />
                                                <GradientStop Offset="1" Color="#FFD1D1F1" />
                                            </LinearGradientBrush>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </Border.Style>
                            <Grid DataContext="{TemplateBinding Model}"
                                  ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                  d:DataContext="{Binding Source={StaticResource CategoriesFilter}}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <ListBox x:Name="PART_Items"
                                         Grid.Row="1"
                                         Grid.ColumnSpan="2"
                                         ItemsPanel="{StaticResource CategoryItemsPanelTemplate}"
                                         ItemsSource="{Binding AvailableValues}"
                                         SelectionMode="Multiple">
                                    <ListBox.Background>
                                        <LinearGradientBrush StartPoint="0.5,1" EndPoint="0.5,0">
                                            <GradientStop Color="#FFFEFEFE" />
                                            <GradientStop Offset="1" Color="#FFD1D1F1" />
                                        </LinearGradientBrush>
                                    </ListBox.Background>
                                    <ListBox.ItemContainerStyle>
                                        <Style TargetType="{x:Type ListBoxItem}">
                                            <Setter Property="Background" Value="{Binding Background, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ListBox}}}" />
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                                        <Grid Margin="3">
                                                            <Grid.ColumnDefinitions>
                                                                <ColumnDefinition Width="Auto" />
                                                                <ColumnDefinition Width="Auto" />
                                                            </Grid.ColumnDefinitions>
                                                            <Grid.RowDefinitions>
                                                                <RowDefinition Height="Auto" />
                                                                <RowDefinition Height="60" />
                                                            </Grid.RowDefinitions>
                                                            <CheckBox VerticalAlignment="Center" IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
                                                            <TextBlock Grid.Column="1"
                                                                       Background="Transparent"
                                                                       Text="{Binding Content.Name,
                                                                                      RelativeSource={RelativeSource TemplatedParent}}" />
                                                            <Border Grid.Row="1"
                                                                    Grid.ColumnSpan="2"
                                                                    BorderThickness="2"
                                                                    Padding="2">
                                                                <Border.BorderBrush>
                                                                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                                                        <GradientStop Offset="0" Color="#FFF6F6FC" />
                                                                        <GradientStop Offset="1" Color="#FFD2D2F1" />
                                                                    </LinearGradientBrush>
                                                                </Border.BorderBrush>
                                                                <Image x:Name="image" Source="{Binding Picture}">
                                                                    <Image.Effect>
                                                                        <MultiBinding Converter="{StaticResource BoolToEffectConverter}">
                                                                            <Binding Mode="OneWay"
                                                                                     Path="IsSelected"
                                                                                     RelativeSource="{RelativeSource TemplatedParent}" />
                                                                            <Binding Path="Model.IsActive" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type bsFilter:MultiValueFilterView}}" />
                                                                        </MultiBinding>
                                                                    </Image.Effect>
                                                                </Image>
                                                            </Border>
                                                        </Grid>

                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </ListBox.ItemContainerStyle>
                                </ListBox>
                                <TextBlock Grid.Row="0"
                                           Grid.Column="0"
                                           VerticalAlignment="Center"
                                           Background="{TemplateBinding Background}"
                                           Text="Choose category:" />
                                <Button Grid.Column="1"
                                        Background="{TemplateBinding Background}"
                                        Command="bsFilter:FilterCommand.Clear"
                                        Content="View all categories"
                                        ToolTip="All categories" />
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </bsFilter:MultiValueFilterView.Style>

</bsFilter:MultiValueFilterView>
